package com.hk.housekeeping.order.controller.order;

import com.hk.housekeeping.order.entity.Order;
import com.hk.housekeeping.order.service.impl.OrderPageSevImpl;
import com.hk.housekeeping.order.utils.PageUtils;
import com.hk.housekeeping.order.utils.ResponseCode;
import com.hk.housekeeping.order.utils.ResponseEntity;
import com.hk.housekeeping.order.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/order/page")
public class OrderPageController extends HttpServlet {
    private OrderPageSevImpl orderPageSev = new OrderPageSevImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int page = Integer.parseInt(req.getParameter("page"));
        int pageSize = Integer.parseInt(req.getParameter("pageSize"));
        ResponseEntity entity = null;
        //调用业务逻辑
        try {
            PageUtils<List<Order>> pageObj = orderPageSev.getPageList(page, pageSize);
            entity = ResponseEntity.success(pageObj);
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(ResponseCode.ORDER_DATA_GET_ERROR);
        }

        //传递数据
        ResponseUtils.deliver(resp, entity);
    }
}
